<?php


namespace app\api\controller;


use app\common\model\Member;

class Base
{
    public function testGet()
    {
        $test = get_param('test');
        echo '这是服务端接收到的数据:key => test' . ' | value => ' . $test;
    }
  public function login(){
      $mobile = post_param('mobile');
      $password = post_param('password');
      if (empty($mobile)  || empty($password))output_error_param();
      $memberModel = new Member();
      $condition = array();
      $condition[] = ['member_mobile','=',$mobile];
      $condition[] = ['member_password','=',md5_encrypt($mobile,$password)];
      $data = $memberModel->where($condition)->find();
      if (empty($data)) output_error('账号或密码错误~');
      $token = md5_encrypt(time(),$data['member_id']);
      $updata = array();
      $updata['member_token'] = $token;
      $memberModel->where('member_id','=',$data['member_id'])->update($updata);
      output_data($token);
  }

  public function register()
  {
      $mobile = post_param('mobile');
      $password = post_param('password');
      if (empty($mobile) || empty($password)) output_error_param();
      $memberModel = new Member();
      $data = $memberModel->where('member_mobile', '=', $mobile)->find();
      if (!empty($data)) output_error('账号已存在');
      $data = array();
      $data['member_mobile'] = $mobile;
      $data['member_password'] = md5_encrypt($mobile, $password);
      $data['member_name'] = '用户' . $mobile;
      $data['add_time'] = time();
      if ($memberModel->insert($data)) output_success();
      output_error('注册失败');
  }
}